package tw.org.iii.httpsample;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import org.apache.http.util.ByteArrayBuffer;
import org.apache.http.util.EncodingUtils;

import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;

@SuppressLint("NewApi")
public class ActMain extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.actmain);
		
		StrictMode.ThreadPolicy l_policy = 
				new StrictMode.ThreadPolicy.Builder().permitAll().build();
		 StrictMode.setThreadPolicy( l_policy);
		
		try {
			
			URL url=new URL("http://ent.msn.com.tw/tv/playtime.aspx?id=050");						
			URLConnection conn=url.openConnection();
			InputStream streamIn=conn.getInputStream();
			BufferedInputStream bufferIn=
					new BufferedInputStream(streamIn);
			
			
			ByteArrayBuffer l_byteBuffer=
					new ByteArrayBuffer(bufferIn.available());
			int intDataCount=0;
			while((intDataCount=bufferIn.read())!=-1){
				l_byteBuffer.append((byte)intDataCount);
			}
			
			String strContent=EncodingUtils.getString(
					l_byteBuffer.toByteArray(), "utf-8");
			lbl=(TextView)findViewById(R.id.lblHttp);
			lbl.setText( strContent);
			
			
		} catch (MalformedURLException e) {
			lbl.setText(e.getMessage());
			e.printStackTrace();
		}catch (IOException e) {
			lbl.setText(e.getMessage());
			e.printStackTrace();
		}catch (Exception e) {
			lbl.setText(e.getMessage());
			e.printStackTrace();
		}
		

		
		
		
		
		
		
		
	}
	TextView lbl =null;


}
